package com.cwj;

import java.util.Arrays;
import java.util.List;
import java.util.RandomAccess;

/**
 * Variable used in lambda expression should be final or effectively final
 * @author wujie.chen
 * 2021/9/16 17:26
 */
public class FinalTest {


    public static void main(String[] args) {
        List<String> list = Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "0");
        StringBuilder hello = new StringBuilder("A");
        appendStr(hello, "e");
        list.parallelStream().forEach(e -> {
            appendStr(hello, "e");
        });
//        hello = new StringBuilder("B");
        System.out.println(hello.toString());

    }

    public static void appendStr(StringBuilder hello, String s){
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        hello.append(s);
    }

    public void test( int b){
        int a = 1;
        new Thread(){
            @Override
            public void run() {
                System.out.println(a);
                System.out.println(b);
            }
        }.start();
    }
    public void test2(int b) {
        int a = 10;
        String s = "sd";
        RandomAccess randomAccess = new RandomAccess() {
            @Override
            public String toString() {
                System.out.println(a);
                System.out.println(b);
                System.out.println(s);
                return super.toString();
            }
        };
        randomAccess.toString();
    }
}
